package com.jss.lanouhn.fristapp.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.adapters.SelecterVPAdapter;
import com.jss.lanouhn.fristapp.fragments.Fragment_Selecter_Comment;
import com.jss.lanouhn.fristapp.fragments.Fragment_Selecter_Details;
import com.jss.lanouhn.fristapp.fragments.Fragment_Selecter_Sample;

import java.util.ArrayList;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

/**
 * Created by lanouhn on 16/9/5.
 */
public class SelecterDetails extends AppCompatActivity implements View.OnClickListener{
    private String id;
    private TabLayout tablayout;
    private ViewPager viewPager;
    private TextView tv_purchase;
    private ImageView iv_share, iv_likes, iv_back,iv_comment;
    private ArrayList<String> tabNames;
    private ArrayList<Fragment> fragemnts;
    private Intent intent;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_selecter_detail);

        initView();
        initDate();
        initEvent();
    }

    public String getId(){
        intent = getIntent();
        id = intent.getStringExtra("id");
        Log.d("present", id+"ss");
        return id;
    }
    private void initView() {
        viewPager = (ViewPager) findViewById(R.id.vp_selecter_details);
        tablayout = (TabLayout) findViewById(R.id.tl_selecter_details);
        tv_purchase= (TextView) findViewById(R.id.tv_selecter_purchase);
        iv_share= (ImageView) findViewById(R.id.iv_selcter_share);
        iv_likes= (ImageView) findViewById(R.id.iv_likes);
        iv_back= (ImageView) findViewById(R.id.iv_selecter_back);
        iv_comment= (ImageView) findViewById(R.id.iv_comment);
        tv_purchase.setOnClickListener(this);
        iv_share.setOnClickListener(this);
        iv_back.setOnClickListener(this);
////        iv_likes.setOnClickListener(this);
////        iv_comment.setOnClickListener(this);

    }
    private void initDate() {
        tabNames=new ArrayList<String>();
        tabNames.add("单品");
        tabNames.add("详情");
        tabNames.add("评论");
        fragemnts=new ArrayList<Fragment>();
        fragemnts.add(new Fragment_Selecter_Sample());
        fragemnts.add(new Fragment_Selecter_Details());
        fragemnts.add(new Fragment_Selecter_Comment());
        viewPager.setAdapter(new SelecterVPAdapter(getSupportFragmentManager(),tabNames,fragemnts));
        tablayout.setupWithViewPager(viewPager);
        viewPager.setCurrentItem(0);

    }

    private void initEvent() {
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                 if (position==2){
                     iv_comment.setVisibility(View.VISIBLE);
                 }else {
                     iv_comment.setVisibility(View.INVISIBLE);
                 }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });



    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_comment:



                break;
            case R.id.iv_selecter_back:
                finish();
                break;

            case R.id.iv_likes:


                break;
            case R.id.iv_selcter_share:
                showShare();


                break;

            case R.id.tv_selecter_purchase:
                Intent intent=new Intent(Intent.ACTION_VIEW);
                String purUrl=getIntent().getStringExtra("url");
                intent.setData(Uri.parse(purUrl));
                startActivity(intent);
                break;


        }

    }
    private void showShare() {
        ShareSDK.initSDK(this);
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

      // 分享时Notification的图标和文字  2.5.9以后的版本不调用此方法
        //oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
//        oks.setTitle(getString(R.string.share));
        // titleUrl是标题的网络链接，仅在人人网和QQ空间使用
        oks.setTitleUrl("http://sharesdk.cn");
        // text是分享文本，所有平台都需要这个字段
        oks.setText("我是分享文本");
        //分享网络图片，新浪微博分享网络图片需要通过审核后申请高级写入接口，否则请注释掉测试新浪微博
        oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/02/26/owWpLZo_638x960.jpg");
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        //oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl("http://sharesdk.cn");
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("我是测试评论文本");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite(getString(R.string.app_name));
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl("http://sharesdk.cn");

// 启动分享GUI
        oks.show(this);
    }
}
